import MatchGameConfig from "./MatchGameConfig";
import ObstacleConfig, { ObstacleTargetName } from "./ObstacleConfig";
import UiManager from "./UiManage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TargetEditorItem extends cc.Component {
@property({
type: cc.Enum({
MatchItem: 1,
PropItem: 2,
ObstacleItem: 3,
Null: 4
}),
displayName: '方块类型',
visible: true
})
squareType = 1;

@property({
    type: cc.Enum(MatchGameConfig.MatchItemType),
    displayName: '棋子目标类型',
    visible() {
        return this.squareType === 1;
    }
})
matchType = MatchGameConfig.MatchItemType.Null;

@property({
    type: cc.Enum(MatchGameConfig.PropType),
    displayName: '道具类型',
    visible() {
        return this.squareType === 2;
    }
})
propType = MatchGameConfig.PropType.LightingBall;

@property({
    type: cc.Enum(MatchGameConfig.TargetObstacleType),
    displayName: '障碍物目标类型',
    visible() {
        return this.squareType === 3;
    }
})
obstacleType = MatchGameConfig.TargetObstacleType.ColorBottle;

@property(cc.Integer)
targetCount = 0;

@property(cc.Sprite)
sprite = null;

squareTypeStr = '';
index = 0;
targetInfo = null;

onLoad() {
    this.init(null);
}

init(e) {
    if (e) {
        const { squareType, itemType, tootalCount, squareTypeStr, index } = e;
        this.squareTypeStr = squareTypeStr;
        this.index = index;
        this.squareType = squareType;
        if (this.squareType === 1) {
            this.matchType = itemType;
        } else if (this.squareType === 3) {
            this.obstacleType = itemType;
        } else if (this.squareType === 2) {
            this.propType = itemType;
        }
        this.targetCount = tootalCount;
    }
    this.targetInfo = this.getTargetInfo();
    if (this.squareType === 1) {
        this.setMatchImg(this.matchType, this.sprite);
    } else if (this.squareType === 3) {
        this.setObstacleImg(this.obstacleType, this.sprite);
    } else if (this.squareType === 2) {
        this.setPropImg(this.propType, this.sprite);
    }
}

setTargetCount(e) {
    this.targetCount = e;
}

getTargetInfo() {
    let itemType = null;
    if (this.squareType === 1) {
        itemType = this.matchType;
    } else if (this.squareType === 3) {
        itemType = this.obstacleType;
    } else if (this.squareType === 2) {
        itemType = this.propType;
    }
    const targetInfo = {
        squareType: this.squareType,
        itemType: itemType,
        tootalCount: this.targetCount
    };
    return this.targetCount ? targetInfo : null;
}

setMatchImg(e, t) {
    const a = `imgs/game/matchItem/Items-MatchItem-${e}`;
    UiManager.loadSpriteFrameInDeepPath(t, a);
}

setPropImg(e, t) {
    const a = `imgs/game/props/items-${e}`;
    console.log('path', a);
    UiManager.loadSpriteFrameInDeepPath(t, a);
}

setObstacleImg(e, t) {
    let a = "";
    switch (e) {
        case MatchGameConfig.TargetObstacleType.WoodenBox:
            a = ObstacleTargetName.WoodenBox;
            break;
        case MatchGameConfig.TargetObstacleType.ColorBox:
            a = ObstacleTargetName.ColorBox;
            break;
        case MatchGameConfig.TargetObstacleType.Grass:
            a = ObstacleTargetName.Grass;
            break;
        case MatchGameConfig.TargetObstacleType.GrassLand:
            a = ObstacleTargetName.GrassLand;
            break;
        case MatchGameConfig.TargetObstacleType.Egg:
            a = ObstacleTargetName.Egg;
            break;
        case MatchGameConfig.TargetObstacleType.ColorBottle:
            a = ObstacleTargetName.ColorBottle;
            break;
        case MatchGameConfig.TargetObstacleType.Vase:
            a = ObstacleTargetName.Vase;
            break;
        case MatchGameConfig.TargetObstacleType.Honey:
            a = ObstacleTargetName.Honey;
            break;
        case MatchGameConfig.TargetObstacleType.Icicle:
            a = ObstacleTargetName.Icicle;
            break;
        case MatchGameConfig.TargetObstacleType.Pearl:
            a = ObstacleTargetName.Pearl;
            break;
        case MatchGameConfig.TargetObstacleType.Oyster:
            a = ObstacleTargetName.Oyster;
            break;
        case MatchGameConfig.TargetObstacleType.Flowerpot:
            a = ObstacleTargetName.Flowerpot;
            break;
        case MatchGameConfig.TargetObstacleType.Stone:
            a = ObstacleTargetName.Stone;
            break;
        case MatchGameConfig.TargetObstacleType.SafeBox:
            a = ObstacleTargetName.SafeBox;
            break;
        case MatchGameConfig.TargetObstacleType.PorcelainPig:
            a = ObstacleTargetName.PorcelainPig;
            break;
        case MatchGameConfig.TargetObstacleType.CupboardPlate:
            a = "cupboard_item";
            break;
        case MatchGameConfig.TargetObstacleType.MagicHat:
            a = ObstacleTargetName.Gem;
            break;
        case MatchGameConfig.TargetObstacleType.Mail:
            a = ObstacleTargetName.Mail;
            break;
        case MatchGameConfig.TargetObstacleType.Bird:
            a = ObstacleTargetName.Bird;
            break;
        case MatchGameConfig.TargetObstacleType.GoldCoin:
            a = ObstacleTargetName.GoldCoin;
            break;
        case MatchGameConfig.TargetObstacleType.PurpleFlower:
            a = ObstacleTargetName.PurpleFlower;
            break;
        case MatchGameConfig.TargetObstacleType.Candlebox:
            a = ObstacleTargetName.Candlebox;
            break;
        case MatchGameConfig.TargetObstacleType.Rock:
            a = ObstacleTargetName.Rock;
            break;
        case MatchGameConfig.TargetObstacleType.BirdNest:
            a = ObstacleTargetName.BirdNest;
            break;
        case MatchGameConfig.TargetObstacleType.CupHolder:
            a = ObstacleTargetName.CupHolder;
            break;
    }
    const o = `imgs/game/obstacle/${a}`;
    UiManage.loadSpriteFrameInDeepPath(t, o);
}
}